package com.aceitunaproject.mapdisplay.model.map;

/**
 * Represents a position on the Map.
 */
public class Position {
    public final int x, y;

    /**
     * Creates a new object with the given position.
     * 
     * @param posX
     *            The x-coordinate for this position.
     * @param posY
     *            The y-coordinate for this position.
     */
    public Position(int posX, int posY) {
        x = posX;
        y = posY;
    }

    /**
     * Returns the x-coordinate of this Position.
     * 
     * @return The x-coordinate of this Position.
     */
    public int getX() {
        return x;
    }

    /**
     * Returns the y-coordinate of this Position.
     * 
     * @return The y-coordinate of this Position.
     */
    public int getY() {
        return y;
    }

    /**
     * Compares the other Position based on the coordinates.
     * 
     * @param other the reference object with which to compare.
     * @return true iff the coordinates match.
     */
    @Override
    public boolean equals(Object other) {
        if (this == other) {
            return true;
        } else if (other == null) {
            return false;
        } else if (!(other instanceof Position)) {
            return false;
        } else {
            return x == ((Position) other).x && y == ((Position) other).y;
        }
    }

    /**
     * Returns a hash code value. The current implementation (which may
     * change at any time) works well as long as the maximum coordinates fit
     * in 16 bits.
     * 
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        return x | (y << 16);
    }

    /**
     * Returns a string representation of the object.
     * 
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "(" + x + ", " + y + ")";
    }
}
